//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.haimi.shiguang.utils;

import android.text.TextUtils;

import java.io.UnsupportedEncodingException;

/**
 * @author changsunhaipeng
 */
public class StringUtil {
    public static final String CHARSET_UTF8 = "utf-8";
    public static final String CHARSET_GB2312 = "GB2312";

    public StringUtil() {
    }

    public static String bytes2String(byte[] inBytes) {
        return bytes2String(inBytes, "GB2312");
    }

    public static String bytes2String(byte[] inBytes, String charset) {
        String output = null;
        if(inBytes != null && inBytes.length > 0) {
            try {
                output = new String(inBytes, charset);
            } catch (UnsupportedEncodingException var4) {
                output = null;
            }
        }

        return output;
    }

    public static byte[] String2bytes(String inString) {
        byte[] output;
        try {
            output = inString.getBytes("utf-8");
        } catch (UnsupportedEncodingException var3) {
            output = null;
        }

        return output;
    }

    public static int toInt(String str) {
        return toInt(str, -1);
    }

    public static int toInt(String str, int defaultValue) {
        int value = defaultValue;
        if(!TextUtils.isEmpty(str)) {
            try {
                value = Integer.parseInt(str);
            } catch (NumberFormatException var4) {
                value = defaultValue;
            }
        }

        return value;
    }

    public static float toFloat(String str, float defaultValue) {
        float value = defaultValue;
        if(!TextUtils.isEmpty(str)) {
            try {
                value = Float.parseFloat(str);
            } catch (NumberFormatException var4) {
                value = defaultValue;
            }
        }

        return value;
    }

    public static long toLong(String str, long defaultValue) {
        long value = defaultValue;
        if(!TextUtils.isEmpty(str)) {
            try {
                value = Long.parseLong(str);
            } catch (NumberFormatException var6) {
                value = defaultValue;
            }
        }

        return value;
    }

    public static String subString(String content, int length) {
        return content.length() < length?content:content.substring(0, length);
    }
}
